<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Map</title>
</head>

<body>
    <script>
        /*
            Map类型数据支持两种方式初始化, 其实Map就像换了种方式的对象类型，而Set更像是换了种方式的数组
                1. 初始化时直接写数据, 
                    let map = new Map([
                        [key,value],
                        [key,value],
                        ...
                    ])
                2. 先弄个空的，再调用set(key,value)方法传入
        */
        let m1 = new Map([
            ['name', 'mikaisa'],
            ['age', 18]
        ]);
        for (let item of m1) {
            console.log(item); //其实就是[key,value]
        }

        console.log('----------------------------------------');

        // keys()键名的迭代器  entries()键值对的迭代器  values()值的迭代器
        for (let key of m1.keys()) {
            console.log(key);
        }

        console.log('----------------------------------------');

        // entries()键值对的迭代器
        for (let entry of m1.entries()) {
            console.log(entry);
        }

        console.log('----------------------------------------');

        // values()值的迭代器
        for (let value of m1.values()) {
            console.log(value);
        }

        console.log('----------------------------------------');

        // set get has delete size(这个是属性不是方法) clear这些方法可以用于Map实例，看名字你就应该知道都是干嘛的了吧
        let map = new Map();
        map.set('name', ',mikaisa');
        map.set('age', 18);
        map.set('sex', '男');
        console.log(map.get('sex'));
        console.log(map.has('name'));
        console.log(map.delete('sex'));
        console.log(map.size);
        console.log(map.clear());
        console.log(map, map.size);

        console.log('----------------------------------------');

        // 同样，Map类型的数据也支持forEach
        new Map([
            ['name','mikaisa'],
            ['age',18]
        ]).forEach((value,key,self)=>{
            console.log(value,key,self);
        })
    </script>
</body>

</html>